module lang.d.sts.declarations.dimport;

import lang.d.sts.declarations.ddeclaration;
import lang.d.visitors.dvisitor;

class DImport: DDeclaration {
    private string myName;
    private string myAliasIdentifier;
    private string[][string] myBinds;

    public this(in string name, in string aliasIdentifier, uint attribute) {
        super(attribute);
        myName = name;
        myAliasIdentifier = aliasIdentifier;
    }

    public void addBind(in string realName, in string newName) {
        if (newName == "") {
            if (newName in myBinds) {
                myBinds[newName] ~= realName;
            } else {
                myBinds[newName] = [realName];
            }
        } else {
            myBinds[newName] = [realName];
        }
    }

    public string getAliasIdentifier() const {
        return myAliasIdentifier;
    }

    public string getName() const {
        return myName;
    }

    // COMPILER_BUG_3745
    public string[] getKeys() {
        return myBinds.keys;
    }

    public string[][string] getBindList() {
        return myBinds;
    }

    public string getPrefix() {
        if (myAliasIdentifier != "") {
            return myAliasIdentifier;
        }
        if (isAttributeSet(STATIC)) {
            return myName;
        }
        return "";
    }

    override public void accept(DVisitor visitor) {
        visitor.visitImport(this);
    }
}
